function getCAcardNum(){
	var idCard="11111111";//"1111111111111111"
	//idCard = getGlobalVar("virtualCaId");//add
	/*if(typeof(CAManager) != "undefined"){
		idCard = CAManager.cardSerialNumber;
	} else if(typeof(hardware) != "undefined"){
		idCard = hardware.smartCard.serialNumber;
	}*/
	return idCard;
}
try{
var account = GlobalVarManager.getItemStr("account");
var playIp = "http://vod.fjgdwl.com:80/gldb/NEW_UI/vodPlay/";//去vod播放的路径
var palyBackUrl = "";//播放返回的链接
var movieObj;
var area_code = VOD.areaCode;
if(area_code == ""){
	area_code = VOD.server.regionId;
}
if(area_code == ""){
	area_code = VOD.server.nodeGroupID;
}
}catch(e){
console.log(e);	
}

var marqueeData= [
{"id":"111","content":"欢迎进入泰宁县下渠镇——田园下渠！"},
{"id":"111","content":"三明市流动舞台车百场文化下基层巡演活动泰宁站完美收官"},
{"id":"111","content":"守护绿水青山，“巾帼护河”在行动"}
];// 首页底部的marquee数据
var marqueePos= 0; // 首页底部marquee当前显示数据在数组中的下标
var marqueeTimer= -1; // 首页底部的marquee计时器	
/* 首页底部跑马灯处理 - 开始 */
function startMarquee() {
    var id = marqueePos % 2;
    var anotherId;

    clearTimeout(marqueeTimer);
    $("style0Note" + id).style.webkitTransitionDuration = "0ms";
    $("style0Note" + id).style.top = "23px";
    $("style0Note" + id).style.webkitTransitionDuration = "300ms";
    $("style0Note" + id).innerText = marqueeData[marqueePos].content; // menu.js编码与页面不一致，这里需要转一下
    $("style0Note" + id).style.top = "0px";
    anotherId = id == 0 ? 1 : 0;
    $("style0Note" + anotherId).style.top = "-23px";
    if (marqueeData.length == 1) return;
    marqueePos++;
    if (marqueePos > marqueeData.length - 1) marqueePos = 0;
    marqueeTimer = setTimeout(startMarquee, 10000);
}

function stopMarquee() {
	$('style0Note0').innerHTML = '';
	$('style0Note1').innerHTML = '';
    marqueeData = [];
    marqueePos = 0;
    clearTimeout(marqueeTimer);
}
/* 首页底部跑马灯处理 - 结束 */
function luobrajax(opt) {
	opt = opt || {};
	opt.method = opt.method.toUpperCase() || 'POST';
	opt.url = opt.url || '';
	opt.async = opt.async || true;
	opt.data = opt.data || null;
	opt.success = opt.success || function () {};
	var xmlHttp = null;
	if (XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	else {
		xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	}var params = [];
	for (var key in opt.data){
		params.push(key + '=' + opt.data[key]);
	}
	var postData = params.join('&');
	if (opt.method.toUpperCase() === 'POST') {
		xmlHttp.open(opt.method, opt.url, opt.async);
		xmlHttp.setRequestHeader('Content-Type', 'application/xml;charset=utf-8');
		xmlHttp.send(opt.data);
	}
	else if (opt.method.toUpperCase() === 'GET') {
		xmlHttp.open(opt.method, opt.url + '?' + postData, opt.async);
		xmlHttp.send(null);
	} 
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
			opt.success(xmlHttp.responseText);
		}
	};
}
function checkSavedProgram(assetId,_type){
	var idCard = getCAcardNum();
	luobrajax({
		method: 'POST',
		url: 'http://10.215.0.12:8080/CheckSavedProgram?dataType=json',
		data:"<?xml version='1.0' encoding='UTF-8' standalone='yes'?><CheckSavedProgram assetId='" + assetId + "' portalId='1' client='"+idCard+"' account='"+account+"' folderAssetId='" + assetId + "' profile='1.0' languageCode='zh-CN'/>",
		success: function (response) {
			Utility.println("luobr++ CheckSavedProgram====" + response);
			var json = eval('('+response+')');
			if(_type){//请求断点
				if(json.bookmarkFlag == "true"){
					getResumeParams(assetId,json.timePosition);
				}else{
					getPlayParams(assetId);
				}
			}else{//保存播放记录
				if(json.bookmarkFlag == "true"){
					//存在断点，保存到观看记录中
					//$("bottom_text").innerHTML = "观看记录保存中";
					ajaxForAddLookRecord(assetId,oparateObj.recordTitle,json.timePosition+"000");
				}
			}
			
		}
	});
}

//获取详情为了断点播放用，恶心的同洲接口
function getDetailData(_assetId){
	luobrajax({
		method: 'POST',
		url: 'http://10.215.0.12:8080/GetItemData?dataType=json',
		data:"<?xml version='1.0' encoding='UTF-8' standalone='yes'?><GetItemData titleAssetId='" + _assetId + "' portalId='1' client='" + CAManager.cardSerialNumber + "' account='" + account + "' languageCode='Zh-CN' profile='1'/>",
		success: function (response) {
			Utility.println("luobr++ details====" + response);
			var json = eval('('+response+')');
			movieObj = json.selectableItem;
			Utility.println("luobr++ movieObj====" + movieObj.previewAssetId);
			checkSavedProgram(_assetId,1);
		}
	});
}
//从断点播放
function getResumeParams(_assetId,_timePosition){
	var idCard = getCAcardNum();
	luobrajax({
		method: 'POST',
		url: 'http://10.215.0.12:8080/SelectionResume?dataType=json',
		data:"<?xml version='1.0' encoding='UTF-8' standalone='yes'?><SelectionResume portalId='1'  client='" + idCard + "' account='" + account + "' titleAssetId='" + _assetId + "' purchaseToken='" + _timePosition +"' titleProviderId='" + movieObj.providerId + "' fromStart='N' />",
		success: function (response) {
			Utility.println("luobr++ SelectionResume====" + response);
			var json = eval('('+response+')');
			//{"purchaseToken":"1809885953","rtsp":"rtsp://10.215.0.50:554/;purchaseToken=1809885953;serverID=10.215.0.12:8080"}
			var rtsp = json.rtsp.split(";");
			var serverId = rtsp[2].split(":");
			var playUrl = rtsp[0] + ";" + rtsp[1] + ";" + serverId[0] + ":8080" + ";areacode=" + area_code + ";client=" + CAManager.cardSerialNumber;
			GlobalVarManager.setItemStr("vodPlayUrl",playUrl);
			window.location.href = playIp + "vodPlay.htm?previewId=" + json.previewAssetId + "&startTime=" + json.startTime + "&purchaseToken=" + json.purchaseToken + "&playCurrName=" + movieObj.titleFull + "&assetId=" + _assetId +  "&providerId=" + movieObj.providerId + "&displayRunTime=" + movieObj.displayRunTime + "&folderAssetId=" + _assetId  + "&resumePoint=" + _timePosition +"&from="+ palyBackUrl;
		}
	});
}
//重头播放
function getPlayParams(_assetId){
	luobrajax({
		method: 'POST',
		url: 'http://10.215.0.12:8080/SelectionStart?dataType=json',
		data:"<?xml version='1.0' encoding='UTF-8' standalone='yes'?><SelectionStart titleAssetId='"+ _assetId +"' folderAssetId='"+ _assetId +"' portalId='1'  client='"+ CAManager.cardSerialNumber +"' account='"+ account +"'/>",
		success: function (response) {
			Utility.println("luobr++ SelectionResume====" + response);
			var json = eval('('+response+')');
			//{"purchaseToken":"1809885953","rtsp":"rtsp://10.215.0.50:554/;purchaseToken=1809885953;serverID=10.215.0.12:8080"}
			var rtsp = json.rtsp.split(";");
			var serverId = rtsp[2].split(":");
			var playUrl = rtsp[0] + ";" + rtsp[1] + ";" + serverId[0] + ":8080" + ";areacode=" + area_code + ";client=" + CAManager.cardSerialNumber;
			GlobalVarManager.setItemStr("vodPlayUrl",playUrl);
			window.location.href = playIp + "vodPlay.htm?previewId=" + json.previewAssetId + "&startTime=" + json.startTime + "&purchaseToken=" + json.purchaseToken + "&playCurrName=" + movieObj.titleFull + "&assetId=" + _assetId + "&providerId=" + movieObj.providerId + "&displayRunTime=" + movieObj.displayRunTime + "&folderAssetId=" + movieObj.folderAssetId + "&resumePoint=0&collectCI=" + movieObj.folderAssetId + "&collectCN=" + movieObj.titlebrief + "&from="+palyBackUrl;
		}
	});
}

// JavaScript Document
var Event = function(_event){
    var keycode = _event.keyCode | _event.which;
    var code = "";
    switch (keycode) {
        case 1:
        case 38: //other browsers
        case 65362: //上
		case 87:
            code = "KEY_UP";
            break;
        case 2:
        case 40: //other browsers
        case 65364: //下
		case 83:
            code = "KEY_DOWN";
            break;
        case 3:
        case 37: //other browsers
        case 65361: //左
		case 65:
            code = "KEY_LEFT";
            break;
        case 4:
        case 39: //other browsers
        case 65363: //右
		case 68:
            code = "KEY_RIGHT";
            break;
        case 13:
        case 65293: //确定
            code = "KEY_SELECT";
            break;
        //case 340:
		case 640:
		case 283:
        case 8: //other browsers
        case 27: //谷歌浏览器返回键返回页面问题，用ESC键暂代
        case 65367: //返回
            code = "KEY_BACK";
            break;
		//case 339:
		case 340:
			code = "KEY_EXIT";
			break;
        case 372:
        case 25: //向前翻页
		case 33:
		case 306:
            code = "KEY_PAGE_UP";
            break;
        case 373:
        case 26: //向后翻页
		case 34:
		case 307:
            code = "KEY_PAGE_DOWN";
            break;
        case 513: //right [Ctrl]
        case 65360: //菜单
		case 72:
            code = "KEY_MENU";
            break;
        case 595: //[+]
        case 63561: //音量加
		case 61:
            code = "KEY_VOLUME_UP";
            break;
        case 596: //[-]
        case 63562: //音量减
		case 45:
            code = "KEY_VOLUME_DOWN";
            break;
        case 597: //[.]
        case 63563: //静音
		case 67:
            code = "KEY_VOLUME_MUTE";
            break;
        case 32:
            code = "KEY_F1";
            break;
        case 33:
            code = "KEY_F2";
            break;
        case 34:
            code = "KEY_F3";
            break;
        case 35:
            code = "KEY_F4";
            break;
        case 49:
            code = "KEY_NUMBER1";
            break;
        case 50:
            code = "KEY_NUMBER2";
            break;
        case 51:
            code = "KEY_NUMBER3";
            break;
        case 52:
            code = "KEY_NUMBER4";
            break;
        case 53:
            code = "KEY_NUMBER5";
            break;
        case 54:
            code = "KEY_NUMBER6";
            break;
        case 55:
            code = "KEY_NUMBER7";
            break;
        case 56:
            code = "KEY_NUMBER8";
            break;
        case 57:
            code = "KEY_NUMBER9";
            break;
        case 48:
            code = "KEY_NUMBER0";
            break;
        case 65307:
            code = "KEY_TRACK";
            break;
        case 36: // 喜爱
		case 76:
            code = "KEY_FAV";
            break;
        case 72: // 回看
            code = "KEY_PALYBACK";
            break;
		case 320://red
		case 832:
			code = "KEY_RED";
			break;
		case 321://green
		case 833:
			code = "KEY_GREEN";
			break;
		case 322://yellow
		case 834:
			code = "KEY_YELLOW";
			break;
		case 323: //蓝键
		case 835:
			code = "KEY_BLUE";
			break;
		case 11001:
		case 10901:
			code = "PLAY_END";
			break;
		case 5210:
		case 5209:
			code = "IPANEL_PLAY_END";
			break;
		case 5226:
			code = "IP_PLAY_5226";
			break;
		default:
			code = keycode;
			break;
		
    }
	return code;
};


var operatorKey=1;
var operator = "";
/*获取operator区域*/
function getOperator(){
	var sysTable = DataAccess.getSystemPropertyTable();
	if(sysTable > 0){
		var data = DataAccess.getProperty(sysTable, "operator");	
		Utility.println("portal getOperator data="+data);
		if(data != null){
			eval('var tmp=' + data);
			operatorKey = tmp.key;  
			Utility.println("portal getOperator operatorKey="+operatorKey);			
			switch(operatorKey){
				case 0:
				case "0":
					operator = "";
					break;
				case 1:
				case "1":
					operator = "FUZHOU";
					break; 
				case 2:
				case "2":
					operator = "NANPING";
					break;
				case 3:
				case "3":
					operator = "NINGDE";
					break;
				case 4:
				case "4":
					operator = "PUTIAN";
					break;
				case 5:
				case "5":
					operator = "SANMING";
					break;
				case 6:
				case "6":
					operator = "ZHANGZHOU";
					break;
				case 7:
				case "7":
					operator = "LONGYAN";
					break;
				case 8:
				case "8":
					operator = "QUANZHOU";
					break;
				case 9:
				case "9":
					operator = "XIAMEN";
					break;
				case 10:
				case "10":
					operator = "FUZHOU";
					break;
				case 20:
				case "20":
					operator = "FUZHOU";
					break;
			}
		}
	}
}
function ajaxForalitime(){
	newajax({
		method: 'POST',
		//url: 'http://192.168.24.74:8080/N2W/req',
		//url: 'http://10.215.0.209:8080/N2W/req',
	url: 'http://114.115.239.114:8180/N2W/req',
	data:{"method":"post","url":"http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp","respChat":"utf-8","contentType":"application/x-www-form-urlencoded","bodyContent":""},
		success: function (response) {
			console.log(response);
			var json = eval('('+response+')');
			var d = new Date(parseInt(json.data.t));
			console.log(d);
			var hour = d.getHours() + "";
			var minute = d.getMinutes() + "";
			var year = d.getFullYear() + "";
			var month = d.getMonth() + 1;
			var day = d.getDate() + "";
			var week;
			if(d.getDay()==0)          week="星期日"
			if(d.getDay()==1)          week="星期一"
			if(d.getDay()==2)          week="星期二"
			if(d.getDay()==3)          week="星期三"
			if(d.getDay()==4)          week="星期四"
			if(d.getDay()==5)          week="星期五"
			if(d.getDay()==6)          week="星期六"
			hour = hour.length > 1 ? hour : "0" + hour;
			minute = minute.length > 1 ? minute : "0" + minute;
			year = year.length > 1 ? year : "0" + year;
			month = month > 9 ? month : "0" + month;
			day = day.length > 1 ? day : "0" + day;
			$("nowTime").innerHTML =  hour + ":" + minute;
			$("year").innerHTML =month + "/" + day;
			$("week").innerHTML = week;
			nowTimeSetTimeout = setTimeout("showNowTime()",60000);
		}
	});
}
<!--时间控制器-->
var nowTimeSetTimeout = -1;					//右下角当前时间计时器
function showNowTime(){
	ajaxForalitime();
}
function newajax(opt) {
        opt = opt || {};
        opt.method = opt.method.toUpperCase() || 'POST';
        opt.url = opt.url || '';
        opt.async = opt.async || true;
        opt.data = opt.data || null;
        opt.success = opt.success || function () {};
        var xmlHttp = null;
        if (XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
        else {
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        }var params = [];
        for (var key in opt.data){
            params.push(key + '=' + opt.data[key]);
        }
        var postData = params.join('&');
        if (opt.method.toUpperCase() === 'POST') {
            xmlHttp.open(opt.method, opt.url, opt.async);
            xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
            xmlHttp.send(postData);
        }
        else if (opt.method.toUpperCase() === 'GET') {
            xmlHttp.open(opt.method, opt.url + '?' + postData, opt.async);
            xmlHttp.send(null);
        } 
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                opt.success(xmlHttp.responseText);
            }
        };
}

function ajaxForWearther(){
	getOperator();
	ajax({
		url: "http://10.215.0.36/weather/sy/"+operator+".js",//queryTitleByIdMobile.shtml?id=" + _id + "&userid=" + caNum,// 请求的URL,可传参数
		type: "GET", //HTTP 请求类型,GET或POST
		dataType: "html", //请求的文件类型html/xml
		onSuccess: function(html){ //请求成功后执行[可选]
			eval(html);
			var info = mainArray;
			var city = iPanel.misc.getUserCharsetStr(info[0].cityName,"UTF8");
			var weather = iPanel.misc.getUserCharsetStr(info[0].t0[0].weather,"UTF8");
			var temperature = iPanel.misc.getUserCharsetStr(info[0].t0[0].temperature,"UTF8");
			if(typeof city != "undefined" && city != "undefined" && city != ""){
				//$("city").innerText = city;
			}
			if(typeof temperature != "undefined" && temperature != "undefined" && temperature != ""){
				$("temperature").innerText = temperature;
			}
			if(typeof weather != "undefined" && weather != "undefined" && weather != ""){
				//$("weather").innerText = weather;
				changeWeather(weather);
			}
		},
		onError:function(){ //请求失败后执行[可选]
			$("temperature").innerText = "暂无天气信息";
		},
        onComplete:function(){// 请求成功.失败或完成(无论成功失败都会调用)时执行的函数[可选]
           // //alert("onComplete");	             			           		  
        },
        post:"", 
        timeout:7000  //请求的超时时间，默认7000ms，也可自行设定[可选]
	});
}
var tempWeather=null;
function changeWeather(_weather){
	switch(_weather){
		case "阵雨":
			tempWeather="images/weather/zhenyu.png";
			break;
		case "暴雪":
			tempWeather="images/weather/baoxue.png";
			break;
		case "暴雨":
			tempWeather="images/weather/baoyu.png";
			break;
		case "暴雨转大暴雨":
			tempWeather="images/weather/baoyuzhuandabaoyu.png";
			break;
		case "大暴雨":
			tempWeather="images/weather/dabaoyu.png";
		case "大暴雨转特大暴雨":
			tempWeather="images/weather/dabaoyuzhuantedabaoyu.png";
			break;
		case "大雾":
			tempWeather="images/weather/dawu.png";
			break;
		case "大雪":
			tempWeather="images/weather/daxue.png";
			break;
		case "大雪转暴雪":
			tempWeather="images/weather/daxuezhuanbaoxue.png";
			break;
		case "大雨":
			tempWeather="images/weather/dayu.png";
			break;
		case "大雨转暴雨":
			tempWeather="images/weather/dayuzhuanbaoyu.png";
			break;
		case "冬雨":
			tempWeather="images/weather/dongyu.png";
			break;
		case "多云":
			tempWeather="images/weather/duoyun.png";
			break;
		case "浮尘":
			tempWeather="images/weather/fuchen.png";
			break;
		case "雷阵雨":
			tempWeather="images/weather/leizhenyu.png";
			break;
		case "雷阵雨伴有冰雹":
			tempWeather="images/weather/leizhenyubanyoubingbao.png";
			break;
		case "雷阵雨冰雹":
			tempWeather="images/weather/leizhenyubingbao.png";
			break;
		case "强沙尘暴":
			tempWeather="images/weather/qiangshachenbao.png";
			break;
		case "晴":
			tempWeather="images/weather/qing.png";
			break;
		case "沙尘暴":
			tempWeather="images/weather/shachenbao.png";
			break;
		case "特大暴雨":
			tempWeather="images/weather/tedabaoyu.png";
			break;
		case "小雪":
			tempWeather="images/weather/xiaoxue.png";
			break;
		case "雾":
			tempWeather="images/weather/wu.png";
			break;
		case "小雪转中雪":
			tempWeather="images/weather/xiaoxuezhuanzhongxue.png";
			break;
		case "小雨":
			tempWeather="images/weather/xiaoyu.png";
			break;
		case "小雨转中雨":
			tempWeather="images/weather/xiaoyuzhuanzhongyu.png";
			break;
		case "扬沙":
			tempWeather="images/weather/yangsha.png";
			break;
		case "阴":
			tempWeather="images/weather/yin.png";
			break;
		case "雨夹雪":
			tempWeather="images/weather/yujiaxue.png";
			break;
		case "阵雪":
			tempWeather="images/weather/zhenxue.png";
			break;
		case "中雪":
			tempWeather="images/weather/zhongxue.png";
			break;
		case "中雪转大雪":
			tempWeather="images/weather/zhongxuezhuandaxue.png";
			break;
		case "中雨":
			tempWeather="images/weather/zhongyu.png";
			break;
		case "中雨转大雨":
			tempWeather="images/weather/zhongyuzhuandayu.png";
			break;
	} 
	//$("weather").innerText =tempWeather;
		$("weather_img").src  = tempWeather;
}

var Q = Query = {
	getFromURL: function(url,parameter){
		var index = url.indexOf("?");
		if (index != -1) {
			var parameterString = url.substr(index + 1);
			var reg = new RegExp("(^|&)" + parameter + "=([^&]*)(&|$)", "i");
			var r = parameterString.match(reg);
			if (r != null){
				return r[2];
			}
		}
		return null;
	},
	get: function(parameter) {
		if (typeof (parameter) == "undefined" || parameter == "") {
			return null;
		}
		var url = window.location.href;		
		var index = url.indexOf("?");
		if (index != -1) {
			var parameterString = url.substr(index + 1);
			var reg = new RegExp("(^|&)" + parameter + "=([^&]*)(&|$)", "i");
			var r = parameterString.match(reg);
			if (r != null){
				return r[2];
			}
		}
		return null;
	},
	getInt:function(parameter,defaultValue){
		var value = parseInt(this.get(parameter));
		return isNaN(value) ? (typeof(defaultValue) == "undefined" ? 0 : defaultValue) : value;
	},
	getDecoded:function(parameter){
		return this.decode(this.get(parameter));
	},
	decode:function(srcStr){
		if(typeof(srcStr) == "undefined"){return null;}
		return decodeURIComponent(srcStr);
	},
	encode:function(srcStr){
		if(typeof(srcStr) == "undefined"){return null;}
		return encodeURIComponent(srcStr);
	},
	getSymbol:function(url){
		return url.indexOf("?") == -1 ? "?" : "&";
	},
	joinURL:function(url,queryString){
		return url + this.getSymbol(url) + queryString;
	},
	createQueryString:function(obj){
		var a = [];
		for(var p in obj){
			if(typeof(obj[p]) == "function" || obj[p] == null || typeof(obj[p])=="undefined") continue;
			a.push(p + "=" + obj[p]);
		}
		return a.join("&");	
	}
};

function $(_id) {
	return document.getElementById(_id);
}

function showTitleForMarquee(_title, _obj, _num) {
	if(_title.length > _num) {
		_obj.innerHTML = "<marquee>" + _title + "</marquee>";
	} else {
		_obj.innerHTML = _title;
	}
}

function showTitleLikeMarquee(_title, _obj, _num, _time) {
	var time_out = 0;
	if(_title.length > _num) {
		var time = _time || 2500;
		
		var tempText = _title;
		var size=Math.ceil(tempText.length/_num);
		var array = [];
		for(var i=0;i<size;i++){
		    var start=i*_num;
		    var end=(i+1)*_num;
			if(end>tempText.length){
			  end=tempText.length;
			}
		    array.push(tempText.substring(start,end));
		}
		var temp=1;
		_obj.innerHTML=array[0];
		if(array.length>1){
		   time_out = setInterval(function(){
		    _obj.innerHTML=array[temp];
			if(temp>=(array.length-1)){
	      		temp=0;
		    }else{
			  temp++;
		    }
		   },time);
		}
	} else {
		_obj.innerHTML = _title;
	}
	return time_out;
}

//制保留2位小数，如：2，会在2后面补上00.即2.00  
function toDecimal2(x) {  
	var f = parseFloat(x);  
	if (isNaN(f)) {  
    	return false;  
    }  
    var f = Math.round(x*100)/100;  
    var s = f.toString();  
    var rs = s.indexOf('.');  
    if (rs < 0) {  
    	rs = s.length;  
        s += '.';  
    }  
    while (s.length <= rs + 2) {  
    	s += '0';  
    }  
    return s;  
}



	function createXHR() {
		if(typeof XMLHttpRequest != "undefined") {
			createXHR = function() {
				return new XMLHttpRequest();
			};
		} else if(typeof ActiveXObject != "undefined") {
			createXHR = function() {
				if(typeof arguments.callee.activeXString != "string") {
					var versions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp"];
					for(var i = 0, len = versions.length; i < len; i++) {
						try {
							var xhr = new ActiveXObject(versions[i]);
							arguments.callee.activeXString = versions[i];
							return xhr;
						} catch(ex) {
							//跳过
							if(len - 1 == i) {
								throw new Error("there is no xmlhttprequest object available");
							}
						}
					}
				} else {
					return new ActiveXObject(arguments.callee.activeXString);
				}
			};
		} else {
			createXHR = function() {
				throw new Error("there is no xmlhttprequest object available");
			};
		}
		return createXHR();
	}
	
	function ajax(_optionsObj, _cfFlag, _time_out) {
		var time_out = _time_out || new Date().getTime();
		var optionsObj = {
			// HTTP 请求类型
			type:        _optionsObj.type || "GET",
			// 请求的文件类型
			dataType:    _optionsObj.dataType,
			// 请求的URL
			url:        _optionsObj.url || "",
			//请求方式，true异步请求，false同步请求
			requestType: _optionsObj.requestType === false ? false:true,
			// 请求的超时时间
			time_out:    _optionsObj.time_out || 10000,
			// 请求成功.失败或完成(无论成功失败都会调用)时执行的函数
			onComplete: _optionsObj.onComplete || function(){},
			onError:    _optionsObj.onError || function(){},
			onSuccess:    _optionsObj.onSuccess || function(){},
			// 服务器端默认返回的数据类型
			data:        _optionsObj.data || "",
			post:        _optionsObj.post || ""
		};
		var cfFlag = _cfFlag || true;
		
		var ajaxZXFlag = true;
		// 强制关闭函数
		var timeOutRD = setTimeout(function(){
			clearTimeout(timeOutRD);
			ajaxZXFlag = false;
			if(!cfFlag) {
				ajax(optionsObj, true, time_out);
			} else {
				optionsObj.onError();
				
				//var time_in = new Date().getTime();
				//var time_c = time_in - time_out;
				//$("msgvalue").innerHTML = "time : " + time_c + " timeOutRD readyState : " + xml.readyState + " and xml.status : " + xml.status;
			}
		}, optionsObj.time_out);
		
		var xml = createXHR();
		xml.onreadystatechange = function() {
			if(xml.readyState == 4 && ajaxZXFlag){
				// 检查是否请求成功
				clearTimeout(timeOutRD);
				if(httpSuccess(xml) && ajaxZXFlag){
					// 以服务器返回的数据作为参数执行成功回调函数
					optionsObj.onSuccess(httpData(xml, optionsObj.dataType ));
				}else{
					optionsObj.onError();					
					//var time_in = new Date().getTime();
					//var time_c = time_in - time_out;
					//$("msgvalue").innerHTML = "time : " + time_c + " timeOutRD readyState : " + xml.readyState + " and xml.status : " + xml.status;
				}
	
				// 调用完成后的回调函数
				optionsObj.onComplete(xml);
				// 避免内存泄露,清理文档
				xml = null;
			}
		}
		var url;
		if(optionsObj.url.indexOf("?") > -1) {
			url = optionsObj.url + "&timestamp=" + new Date().getTime();
		} else {
			url = optionsObj.url + "?timestamp=" + new Date().getTime();
		}
		xml.open(optionsObj.type, url, optionsObj.requestType); 
		if("GET" == optionsObj.type){
			xml.send(null);
		}else{
			xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xml.send(optionsObj.post);	
		}
	}
	
	 // 判断HTTP响应是否成功
    function httpSuccess(r){
        var flag = false;
		try {
			if((r.status >= 200 && r.status <= 300) || r.status == 304) {
				// 如果得不到服务器状态,且我们正在请求本地文件,则认为成功
				flag = true;
			} else if(!r.status && location.protocol == "file:") {
				// 所有200-300之间的状态码 表示成功
				flag = true;
			} else if(navigator.userAgent.indexOf('Safari') >= 0 && typeof r.status == "undefined") {
				// Safari在文档未修改的时候返回空状态
				flag = true;
			} else {
				flag = false;
			}   
        }catch(e){
			flag = false;
		} finally {
			return flag;
		}
        
        // 若检查状态失败,则假定请求是失败的
    }

    // 从HTTP响应中解析正确数据
    function httpData(r, type){
        // 获取content-type的头部
        var ct = r.getResponseHeader("content-type");
        // 如果没有提供默认类型, 判断服务器返回的是否是XML形式
        var data = !type && ct && ct.indexOf('xml') >= 0;

        // 如果是XML则获得XML对象 否则返回文本内容
        data = type == "xml" || data ? r.responseXML : r.responseText;

        // 如果指定类型是script,则以javascript形式执行返回文本
        if(type == "script"){
            eval.call(window, data);
        }

        // 返回响应数据
        return data;
    }
	
	
	

	// 数据串行化 支持两种不同的对象
	// - 表单输入元素的数组
	// - 键/ 值 对应的散列表
	// - 返回串行化后的字符串 形式: name=john& password=test
	
	function serialize(a) {
		// 串行化结果存放
		var s = [];
		// 如果是数组形式 [{name: XX, value: XX}, {name: XX, value: XX}]
		if(a.constructor == Array){
			// 串行化表单元素
			for(var i = 0; i < a.length; i++){
				s.push(a[i].name + "=" + encodeURIComponent( a[i].value ));
			}
			// 假定是键/值对象
		}else{
			for( var j in a ){
				s.push( j + "=" + encodeURIComponent( a[j] ));
			}
		}
		// 返回串行化结果
		return s.join("&");
	}
	/*-----------------------------------------读写盒子全局变量代码---------------------------------*/
function getGlobalVar(_key) {
	if("undefined" != typeof(iPanel)) {
		return iPanel.getGlobalVar(_key) || "";
	} else {
		return getCookie(_key);
	}
}

function setGlobalVar(_key, _value) {
	if("undefined" != typeof(iPanel)) {
		iPanel.setGlobalVar(_key, _value + "");
	} else {
		setCookie(_key, _value + "");
	}
}

//写cookies
function setCookie(name,value) {
	var exp = new Date(); 
	exp.setTime(exp.getTime() +24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";path=/;expires=" + exp.toGMTString();
}
//读取cookies
function getCookie(name) {
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)) return unescape(arr[2]);
	else return null;
}
//删除cookies
function delCookie(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null) document.cookie= name + "="+cval+";path=/;expires="+exp.toGMTString();
}
	
/*-----------------------------------------动态生成对应数据对象--------------------------------------------*/

